#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_btnCalculate_clicked()
{
    QString strCount = ui->textCount->text();
    int count = strCount.toInt();
    QString strPrice = ui->textPrice->text();
    float price = strPrice.toFloat();
    float total = count * price;
    QString strTotal = QString::asprintf("%.2f", total);
    ui->textTotal->setText(strTotal);
}


void MainWindow::on_btnDec_clicked()
{
    QString strDec = ui->textDec->text();
    int dec = strDec.toInt();
    QString str = QString::number(dec, 16);
    str = str.toUpper();
    ui->textHex->setText(str);

    str = QString::number(dec, 2);
    ui->textBin->setText(str);
}

void MainWindow::on_btnBin_clicked()
{
    QString strBin = ui->textBin->text();
    bool ok;
    int bin = strBin.toInt(&ok, 2);
    QString str = QString::number(bin, 10);
    ui->textDec->setText(str);

    str = QString::number(bin, 16);
    str = str.toUpper();
    ui->textHex->setText(str);
}

void MainWindow::on_btnHex_clicked()
{
    QString strHex = ui->textHex->text();
    bool ok;
    int hex = strHex.toInt(&ok, 16);
    QString str = QString::number(hex, 10);
    ui->textDec->setText(str);

    str = QString::number(hex, 2);
    ui->textBin->setText(str);
}
